<template>
  <div>
    <el-date-picker
      v-model="dateScope"
      type="daterange"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
    />
    <el-button type="primary" size="small" @click="queryBasicInfo()">查询</el-button>
    <el-button type="primary" size="small" @click="insertBasicInfo()">新增</el-button>
    <el-table
      highlight-current-row
      :data="tableData"
      border
      style="width: 100%"
    >
      <el-table-column
        prop="ID"
        label="ID"
        width="180"
      />
      <el-table-column
        prop="GATHER_SNO"
        label="采编流水号"
        width="180"
      />
      <el-table-column
        prop="ORDER_DATE"
        label="采编日期"
      />
      <el-table-column
        prop="MEETING_ID"
        label="股东大会ID"
      />
      <el-table-column
        prop="INTERNAL_MEETING_ID"
        label="公司部股东大会ID"
      />
      <el-table-column
        prop="BULLETIN_ID"
        label="公告ID"
      />
      <el-table-column
        prop="SEC_CODE"
        label="证券代码"
      />
      <el-table-column
        prop="SEC_ABBR"
        label="证券简称"
      />
      <el-table-column
        prop="BULLETIN_TYPE"
        label="公告类型"
      />
      <el-table-column
        prop="MEETING_NAME"
        label="股东大会名称"
      />
      <el-table-column
        prop="MEETING_BEGIN_DATE"
        label="股东大会开始日"
      />
      <el-table-column
        prop="MEETING_END_DATE"
        label="股东大会结束日"
      />
      <el-table-column
        prop="IS_TRADE_SYS_VOTE"
        label="是否通过上交所投票"
      />
      <el-table-column
        prop="A_CODE"
        label="A股产品代码"
      />
      <el-table-column
        prop="A_ABBR"
        label="A股简称"
      />
      <el-table-column
        prop="A_REG_DATE"
        label="A股登记日"
      />
      <el-table-column
        prop="A_LAST_DATE"
        label="A股最后交易日"
      />
      <el-table-column
        prop="B_CODE"
        label="B股代码"
      />
      <el-table-column
        prop="B_ABBR"
        label="B股简称"
      />
      <el-table-column
        prop="B_REG_DATE"
        label="B股登记日"
      />
      <el-table-column
        prop="B_LAST_DATE"
        label="B股最后交易日"
      />
      <el-table-column
        prop="PRIORITY_CODE"
        label="优先股代码"
      />
      <el-table-column
        prop="PRIORITY_ABBR"
        label="优先股简称"
      />
      <el-table-column
        prop="PRIORITY_REG_DATE"
        label="优先股登记日"
      />
      <el-table-column
        prop="PRIORITY_LAST_DATE"
        label="优先股最后交易日"
      />
      <el-table-column
        prop="RECOVERY_PRIORITY_CODE"
        label="恢复表决权的优先股代码"
      />
      <el-table-column
        prop="RECOVERY_PRIORITY_ABBR"
        label="恢复表决权的优先股简称"
      />
      <el-table-column
        prop="RECOVERY_PRIORITY_REG_DATE"
        label="恢复表决权优先股登记日"
      />
      <el-table-column
        prop="RECOVERY_PRIORITY_LAST_DATE"
        label="恢复表决权优先股最后交易日"
      />
      <el-table-column
        prop="MEETING_TYPE"
        label="股东大会类型"
      />
      <el-table-column
        prop="BULLETIN_DATE"
        label="公告日期"
      />
      <el-table-column
        prop="TOPIC_NUMBER"
        label="总议案数"
      />
      <el-table-column
        prop="MEETING_ADDR"
        label="开会地点"
      />
      <el-table-column
        prop="MEETING_TIME"
        label="开会时间"
      />
      <el-table-column
        prop="LC_CONFIRM_STATUS"
        label="确认状态"
      />
      <el-table-column
        prop="URL_ADDRESS"
        label="公告URL地址"
      />
      <el-table-column
        prop="TRADEMARKET"
        label="交易市场"
      />
      <el-table-column
        prop="IS_VALID"
        label="是否有效"
      />
      <el-table-column
        prop="PRIORITY_COV_RATIO"
        label="优先股转换比例"
      />
      <el-table-column
        prop="RECOVERY_PRIORITY_COV_RATIO"
        label="恢复表决权优先股转换比例"
      />
      <el-table-column
        prop="MEETING_TIME_STR"
        label="现场开会时间"
      />
      <el-table-column
        prop="SECURITY_TYPE"
        label="证券类型"
      />
      <el-table-column
        prop="SECURITY_SUB_TYPE"
        label="证券子类型"
      />
      <el-table-column
        prop="WEB_TITLE"
        label="上网标题"
      />
      <el-table-column label="操作" width="120">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="small"
            @click.native.prevent="editingBasicInfo(scope.row)"
          >查看会议</el-button>
          <el-button
            type="primary"
            size="small"
            @click.native.prevent="showTopic(scope.row)"
          >查看议案</el-button>
          <el-button
            type="primary"
            size="small"
            :disabled="scope.row.LC_CONFIRM_STATUS!=='0'"
            @click.native.prevent="confirmBasicInfo(scope.row)"
          >{{ scope.row.LC_CONFIRM_STATUS==='1' ? '已审核':'确认' }}</el-button>
          <el-button
            type="primary"
            size="small"
            @click.native.prevent="deleteBasicInfo(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 股东大会编辑-->
    <dialog-component
      v-if="showDialog"
      ref="dialogComponent"
      :dialog-title="basicTitle"
      :item-info="selectBasicInfo"
      @closeDialog="closeDialog"
    />
    <!-- 显示议案 -->
    <topic-form-component
      v-if="showTopicForm"
      ref="topicFormComponent"
      :form-title="basicTitle"
      @closeTopic="closeTopic"
    />
  </div>
</template>

<script>

import { formatterTime, getDate } from '@/utils/DateUtil'
import DialogComponent from '@/components/editing/dialogComponent'
import TopicFormComponent from '@/components/editing/topicForm'

export default {
  name: 'BasicInfo',
  components: { TopicFormComponent, DialogComponent },
  data() {
    return {
      basicTitle: '',
      selectBasicInfo: '',
      showDialog: false,
      showTopicForm: false,
      tableData: [],
      dateScope: [],
      gatherSNO: ''
    }
  },
  methods: {
    queryBasicInfo() {
      const that = this
      that.tableData = []
      const today = getDate(6)
      const tomorrow = getDate(9)
      let startTime = ''
      let endTime = ''
      if (that.dateScope.length === 0) {
        startTime = today
        endTime = tomorrow
      } else if (that.dateScope.length === 1) {
        startTime = formatterTime(that.dateScope[0])
        endTime = today
      } else {
        startTime = formatterTime(that.dateScope[0])
        endTime = formatterTime(that.dateScope[1])
      }

      const data = {
        startTime,
        endTime
      }
      console.log(data)
      that.$store.dispatch('editing/getBasicInfo', data).then(res => {
        if (res.data) {
          console.log(res.data)
          for (let i = 0; i < res.data.length; i++) {
            that.tableData.push(
              { ID: res.data[i]['ID'],
                GATHER_SNO: res.data[i]['GATHER_SNO'],
                ORDER_DATE: res.data[i]['ORDER_DATE'],
                MEETING_ID: res.data[i]['MEETING_ID'],
                INTERNAL_MEETING_ID: res.data[i]['INTERNAL_MEETING_ID'],
                BULLETIN_ID: res.data[i]['BULLETIN_ID'],
                SEC_CODE: res.data[i]['SEC_CODE'],
                SEC_ABBR: res.data[i]['SEC_ABBR'],
                BULLETIN_TYPE: res.data[i]['BULLETIN_TYPE'],
                MEETING_NAME: res.data[i]['MEETING_NAME'],
                MEETING_BEGIN_DATE: res.data[i]['MEETING_BEGIN_DATE'],
                MEETING_END_DATE: res.data[i]['MEETING_END_DATE'],
                IS_TRADE_SYS_VOTE: String(res.data[i]['IS_TRADE_SYS_VOTE']),
                A_CODE: res.data[i]['A_CODE'],
                A_ABBR: res.data[i]['A_ABBR'],
                A_REG_DATE: res.data[i]['A_REG_DATE'],
                A_LAST_DATE: res.data[i]['A_LAST_DATE'],
                B_CODE: res.data[i]['B_CODE'],
                B_ABBR: res.data[i]['B_ABBR'],
                B_REG_DATE: res.data[i]['B_REG_DATE'],
                B_LAST_DATE: res.data[i]['B_LAST_DATE'],
                PRIORITY_CODE: res.data[i]['PRIORITY_CODE'],
                PRIORITY_ABBR: res.data[i]['PRIORITY_ABBR'],
                PRIORITY_REG_DATE: res.data[i]['PRIORITY_REG_DATE'],
                PRIORITY_LAST_DATE: res.data[i]['PRIORITY_LAST_DATE'],
                RECOVERY_PRIORITY_CODE: res.data[i]['RECOVERY_PRIORITY_CODE'],
                RECOVERY_PRIORITY_ABBR: res.data[i]['RECOVERY_PRIORITY_ABBR'],
                RECOVERY_PRIORITY_REG_DATE: res.data[i]['RECOVERY_PRIORITY_REG_DATE'],
                RECOVERY_PRIORITY_LAST_DATE: res.data[i]['RECOVERY_PRIORITY_LAST_DATE'],
                MEETING_TYPE: res.data[i]['MEETING_TYPE'],
                BULLETIN_DATE: res.data[i]['BULLETIN_DATE'],
                TOPIC_NUMBER: res.data[i]['TOPIC_NUMBER'],
                MEETING_ADDR: res.data[i]['MEETING_ADDR'],
                MEETING_TIME: res.data[i]['MEETING_TIME'],
                LC_CONFIRM_STATUS: res.data[i]['LC_CONFIRM_STATUS'],
                URL_ADDRESS: res.data[i]['URL_ADDRESS'],
                TRADEMARKET: res.data[i]['TRADEMARKET'],
                IS_VALID: String(res.data[i]['IS_VALID']),
                PRIORITY_COV_RATIO: res.data[i]['PRIORITY_COV_RATIO'],
                RECOVERY_PRIORITY_COV_RATIO: res.data[i]['RECOVERY_PRIORITY_COV_RATIO'],
                MEETING_TIME_STR: res.data[i]['MEETING_TIME_STR'],
                SECURITY_TYPE: res.data[i]['SECURITY_TYPE'],
                SECURITY_SUB_TYPE: res.data[i]['SECURITY_SUB_TYPE'],
                WEB_TITLE: res.data[i]['WEB_TITLE']
              })
          }
        }
      })
    },
    insertBasicInfo() {
      this.selectBasicInfo = { methodType: 'create' }
      this.showDialog = true
      this.$nextTick(() => {
        this.$refs['dialogComponent'].showDialog = true
      })
    },
    editingBasicInfo(row) {
      this.basicTitle = row['WEB_TITLE']
      this.selectBasicInfo = row
      this.showDialog = true
      this.$nextTick(() => {
        this.$refs['dialogComponent'].showDialog = true
      })
    },
    confirmBasicInfo(row) {
      const that = this
      const ID = row['ID']
      const data = {
        ID
      }
      this.$confirm('此操作将变更改条股东大会信息的确认状态，是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        that.$store.dispatch('editing/confirmBasicInfo', data).then(res => {
          if (res.data === true) {
            this.$message({
              type: 'success',
              message: '确认成功！'
            })
          }
          this.queryBasicInfo()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消确认'
        })
      })
    },
    deleteBasicInfo(row) {
      const that = this
      const ID = row['ID']
      const data = {
        ID
      }
      this.$confirm('此操作将逻辑删除该股东大会信息，是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        that.$store.dispatch('editing/deleteBasicInfo', data).then(res => {
          if (res.data === true) {
            this.$message({
              type: 'success',
              message: '删除成功！'
            })
          }
          this.queryBasicInfo()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    showTopic(row) {
      this.gatherSNO = row['GATHER_SNO']
      console.log(this.gatherSNO)
      setTimeout(() => {
        this.$refs.topicFormComponent.getTopicInfo(this.gatherSNO)
      }, 100)
      this.showTopicForm = true
    },
    closeDialog(flag) {
      if (flag) {
        this.queryBasicInfo()
      }
      this.showDialog = false
    },
    closeTopic(flag) {
      if (flag) {
        console.log('close Topic')
      }
      this.showTopicForm = false
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
